{
	name:"Text",
	importCommand:[{
		key:"{Web}",
		path:"./config"
	},{
		key:"Tool",
		path:"./paint_tool/text.shape"
	}],
	onInit(){
		this.ctrlIndex = 0
		this.on("focusIn",()=>{
			this.ghostCvs.style.cursor="text"
		})
		this.on("focusOut",()=>{
			this.ghostCvs.style.cursor="default"
		})
		this.$event.on(EN.input_done,this.onPick.bind(this))
	},
	onMousemove(pos){
		if(!this.active)return
		this.clearRect()
		let rs = this.$version.queryByAction(Action.Text)
		rs = rs.filter((s)=>{return this.inPath(s.step,pos,s.state)})
		if(!rs.isEmpty())
			this.pathFocus(rs[0])
	},
	onClick(pos){
		if(!this.active)return

		let step = pos
		let scale = this.ghostCtx.zoom
		let rs = this.$version.queryByAction(Action.Text)
		rs = rs.filter((s)=>{return this.inPath(s.step,pos,s.state)})
		
		if(rs.isEmpty()){
			step = pos.assign({
				h:Web.cvsLineHeight*scale
			})
		}
		else{
			this.chache = rs[0].assign()
			step = this.chache.step[0]
		}
		this.step = step
		let {x,y,h} = step
		this.tool.linend([
			{x,y:y-h/2},
			{x,y:y+h/2}],this.ghostCtx)
		let htmlPos = this.ctxPox2html(step)
		this.$event.emit(EN.plugin,{action:"TextPicker"},
			{
			scale,
			placeholder:"输入文字",
			strokeStyle:this.ghostCtx.strokeStyle}.assign(step,htmlPos))
	},
	onPick(data){
		if(!this.active)return
		this.clearRect()
		if(data){
			let step = this.step;
			let scale = this.ghostCtx.zoom
			let text = data.html||data.text
			let w = this.ghostCtx.measureText(text).width*scale
			let id = null

			step.merge({text,w})
			let stepData = {
				step:[step],
				state:this.getContextState()
			}
			if(this.chache)id = this.chache.id
			this.$version.commit(Action.Text,stepData,id)
		}
		this.chache=null
		this.step = null
	}
}